{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Is Unique LCCI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #LCCI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #bit-manipulation #hash-table #string #sorting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #位运算 #哈希表 #字符串 #排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: isUnique"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #判定字符是否唯一"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>实现一个算法，确定一个字符串 <code>s</code> 的所有字符是否全都不同。</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> <code>s</code> = \"leetcode\"\n",
    "<strong>输出:</strong> false \n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> <code>s</code> = \"abc\"\n",
    "<strong>输出:</strong> true\n",
    "</pre>\n",
    "\n",
    "<p><strong>限制：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>0 &lt;= len(s) &lt;= 100 </code></li>\n",
    "\t<li><code>s[i]</code>仅包含小写字母</li>\n",
    "\t<li>如果你不使用额外的数据结构，会很加分。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [is-unique-lcci](https://leetcode.cn/problems/is-unique-lcci/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [is-unique-lcci](https://leetcode.cn/problems/is-unique-lcci/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"leetcode\"', '\"abc\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        c = [0] * 26\n",
    "        for i in range(len(astr)):\n",
    "            c[ord(astr[i]) - ord('a')] += 1\n",
    "            if c[ord(astr[i]) - ord('a')] > 1:\n",
    "                return False\n",
    "            \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        for i in range(len(astr)-1):\n",
    "            a = astr[i]\n",
    "            for j in range(i+1,len(astr)):\n",
    "                if a == astr[j]:\n",
    "                    return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        res = 0\n",
    "        for c in astr:\n",
    "            move = ord(c) - ord(\"a\")\n",
    "            if (res & (1 << move)) != 0:\n",
    "                return False\n",
    "            else:\n",
    "                res |= (1 << move)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def isUnique(self, astr):\n",
    "        \"\"\"\n",
    "        :type astr: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        if len(astr) ==len(set(astr)) :\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        for i in range(len(astr)-1):\n",
    "            a=astr[i]\n",
    "            for j in range(i+1,len(astr)):\n",
    "                if a==astr[j]:\n",
    "                    return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        if len(astr) == len(set(astr)):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        set_str = set([i for i in astr])\n",
    "        return len(set_str)==len(astr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        if (len (astr) == 0 ):\n",
    "            return True\n",
    "        char_list = set()\n",
    "        for char in astr:\n",
    "            if (char in char_list):\n",
    "               return False\n",
    "            char_list.add(char)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, s: str) -> bool:\n",
    "        lst = []  # 用来存储已经遍历过的字符\n",
    "        for char in s:\n",
    "            if char in lst:\n",
    "                return False  # 如果当前字符已经在lst中，说明不是唯一字符，返回False\n",
    "            lst.append(char)  # 将当前字符添加到lst中\n",
    "        return True  # 如果遍历完整个字符串都没有重复字符，返回True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        cnt = set()\n",
    "        for c in astr:\n",
    "            if c in cnt:\n",
    "                return False\n",
    "            cnt.add(c)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "\n",
    "        return len(astr) == len(set(astr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        if len(set(astr)) == len(astr):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        self.astr = astr\n",
    "        ll = []\n",
    "        for i in self.astr:\n",
    "            ll.append(i)\n",
    "        for i in range(len(ll)):\n",
    "            for k in ll:\n",
    "                count = ll.count(k)\n",
    "                if count >= 2:\n",
    "                    return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        mark = 0\n",
    "\n",
    "        for char in astr:\n",
    "            move = ord(char) - ord('a')\n",
    "            if mark & (1 << move) != 0:\n",
    "                return False\n",
    "            else:\n",
    "                mark |= (1 << move)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        dic=dict()\n",
    "        for i in astr:\n",
    "            if i in dic:return False\n",
    "            else:dic[i]=1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        \"\"\"\n",
    "        \"\"\"\n",
    "        if astr is None:\n",
    "            return None\n",
    "\n",
    "        sLen = len(astr)\n",
    "        loop = 0\n",
    "\n",
    "        if sLen < 0 or sLen > 100:\n",
    "            return None\n",
    "        \n",
    "        while loop < sLen:\n",
    "            targetChr = astr[0]\n",
    "            restStr = astr[1:]\n",
    "\n",
    "            if restStr is not None:\n",
    "                if targetChr in restStr:\n",
    "                    return False\n",
    "                else:\n",
    "                    astr = restStr\n",
    "            \n",
    "            loop = loop + 1\n",
    "\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        return astr == \"\" or max(Counter(astr).values()) < 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        return len(astr) == len(set(astr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, s: str) -> bool:\n",
    "        b = \"\"\n",
    "        numbers = 1\n",
    "        for i in s:\n",
    "            if i not in b:\n",
    "                numbers = 1\n",
    "            else:\n",
    "                numbers = 0\n",
    "                break\n",
    "            b = b + i\n",
    "        if numbers == 1:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        for i,atr in enumerate(astr):\n",
    "            atr_after = astr[:i] + astr[i+1:]\n",
    "            if atr in atr_after:\n",
    "                return False\n",
    "        else:\n",
    "            return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        box = []\n",
    "        for c in astr:\n",
    "            if c in box:\n",
    "                return False\n",
    "            else:\n",
    "                box.append(c)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:      \n",
    "        mark=0\n",
    "        markbits=0\n",
    "        for i in astr:\n",
    "            markbits=ord(i)-ord('a')\n",
    "            if(mark&(1<<markbits)!=0):\n",
    "                return False\n",
    "            mark=mark|(1<<markbits)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        len_s = len(astr)\n",
    "        i = 0\n",
    "        while i < len_s-1:\n",
    "            if astr[i] in astr[i+1:]:\n",
    "                return False\n",
    "            i += 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        return len(set(astr)) == len(astr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        '''\n",
    "        字典\n",
    "        '''\n",
    "        # dic = {}\n",
    "        # for i in astr:\n",
    "        #     if i in dic:    return False\n",
    "        #     dic[i] = dic.get(i, 0)+1\n",
    "        # return True\n",
    "\n",
    "        '''\n",
    "        bool数组\n",
    "        '''\n",
    "        bool_letter = [0]*26\n",
    "        for i in astr:\n",
    "            if bool_letter[ord(i) - ord(\"a\")] == 1: return False\n",
    "            bool_letter[ord(i) - ord(\"a\")] = 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        dq = deque()\n",
    "        for i in astr:\n",
    "            if i in dq:\n",
    "                 return False\n",
    "            dq.append(i)\n",
    "                      \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        uniq_s = ''\n",
    "        len_s = len(astr)\n",
    "        i = 0\n",
    "        while i < len_s:\n",
    "            if astr[i] in uniq_s:\n",
    "                return False\n",
    "            else:\n",
    "                uniq_s += astr[i]\n",
    "            i += 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        s = set()\n",
    "        for c in astr:\n",
    "            if c in s:\n",
    "                return False\n",
    "            s.add(c)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        signal = 0\n",
    "        for c in astr:\n",
    "            moveBit = ord(c) - ord('a')\n",
    "            if signal & (1 << moveBit) != 0:\n",
    "                return False\n",
    "            else:\n",
    "                signal |= (1 << moveBit)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        dic = {}\n",
    "        for c in astr:\n",
    "            if c in dic:\n",
    "                return False\n",
    "            else:\n",
    "                dic[c] = 1\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        return len(set(astr))==len(astr)\n",
    "\n",
    "      "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        return len(set(astr)) == len(astr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        return True if len(astr) == len(set(astr)) else False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        flag = 0\n",
    "        for char in astr:\n",
    "            cur = ord(char)-ord('a')\n",
    "            compa = 1<<cur\n",
    "            if flag&compa != 0:\n",
    "                return False\n",
    "            flag = flag|compa\n",
    "        return True   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        n = len(astr)\n",
    "        if n>26:\n",
    "            return False\n",
    "        \n",
    "        for i in range(0,n-1):\n",
    "            for j in range(i+1,n):\n",
    "                if astr[i] == astr[j]:\n",
    "                    return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\r\n",
    "class Solution:\r\n",
    "    def isUnique(self, astr: str) -> bool:\r\n",
    "        return len(set(astr)) == len(astr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def isUnique(self, astr: str) -> bool:\r\n",
    "        return len(set(astr))==len(astr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        self.astr = astr\n",
    "        ll = []\n",
    "        for i in self.astr:\n",
    "            ll.append(i)\n",
    "        for i in range(len(ll)):\n",
    "            for k in ll:\n",
    "                count = ll.count(k)\n",
    "                if count >= 2:\n",
    "                    return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        mark = 0\n",
    "        if len(astr)>26:\n",
    "            return False\n",
    "        for s in astr:\n",
    "            move_bit = ord(s) - ord('a')\n",
    "            if mark & (1<<move_bit) != 0:\n",
    "                return False\n",
    "            \n",
    "            mark |= 1<<move_bit\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        seen=set()\n",
    "        for item in astr:\n",
    "            if item not in seen:\n",
    "                seen.add(item)\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        str1=set(astr)\n",
    "        for i in str1:\n",
    "            cnt=astr.count(i)\n",
    "            if cnt>1:\n",
    "                return False\n",
    "                break\n",
    "        else:\n",
    "            return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        return all(astr.count(i)==1 for i in astr)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        return len(astr) == len(set(astr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        flags = True\n",
    "        for i in range(len(astr)-1):\n",
    "            j = i + 1\n",
    "            while j < len(astr):\n",
    "                if astr[i] == astr[j]:\n",
    "                    flags = False\n",
    "                    return flags\n",
    "                j = j + 1\n",
    "        return flags"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        count = [0] * 26\n",
    "        for s in astr:\n",
    "            count[ord(s) - ord('a')] += 1\n",
    "        \n",
    "        for c in count:\n",
    "            if c >= 2:\n",
    "                return False\n",
    "\n",
    "        return True\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        se = set(astr)\n",
    "        return True if len(se) == len(astr) else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        record = set()\n",
    "        for i in range(len(astr)):\n",
    "            if astr[i] not in record:\n",
    "                record.add(astr[i])\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        c = set()\n",
    "        for i in astr:\n",
    "            if i in c:\n",
    "                return False\n",
    "            c.add(i)\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        s = \"\"\n",
    "        for i in astr:\n",
    "            if i in s:\n",
    "                return False\n",
    "            s += i\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        return len(astr) == len(set(astr))\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        s = sorted(astr)\n",
    "        for i in range(0,len(astr)-1):\n",
    "            if s[i] == s[i+1]:\n",
    "                return False\n",
    "        return True\n",
    "            \n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        if len(set(astr))<len(astr):\n",
    "            return False\n",
    "        elif len(set(astr))==len(astr):\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        map = {}\n",
    "        for i in astr:\n",
    "            if map.get(i,None)==None:\n",
    "                map[i] = 1\n",
    "            else:\n",
    "                map[i]+=1\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        set_s = set(astr)\n",
    "        if len(astr) == len(set_s):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        bitVec = 0\n",
    "        base = ord('a')\n",
    "        for char in astr:\n",
    "            diff = ord(char) - base\n",
    "            value = 1 << diff\n",
    "            if bitVec & value:\n",
    "                return False\n",
    "            bitVec |= value\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        set_s = set(astr)\n",
    "        if len(astr) == len(set_s):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "\n",
    "        if len(astr)>26:\n",
    "            return False\n",
    "        a = ''\n",
    "        for c in astr:\n",
    "            if c in a:\n",
    "                return False\n",
    "            \n",
    "            a = a + c\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def isUnique(self, astr):\n",
    "        \"\"\"\n",
    "        :type astr: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        return (len(set(astr))==len(astr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        ans = 0\n",
    "        for s in astr:\n",
    "            x = 1 << (ord(s) - ord('a'))\n",
    "            if (ans & x) == x:\n",
    "                return False\n",
    "            else:\n",
    "                ans |= x\n",
    "            \n",
    "\n",
    "        return True\n",
    "                    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        if not astr:\n",
    "            return True\n",
    "        counter_string = Counter(astr)\n",
    "        counter_list = counter_string.values()\n",
    "        if max(counter_list)>1:\n",
    "            return False\n",
    "        else: return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        self.astr = astr\n",
    "        ll = []\n",
    "        for i in self.astr:\n",
    "            ll.append(i)\n",
    "        for i in range(len(ll)):\n",
    "            for k in ll:\n",
    "                count = ll.count(k)\n",
    "                if count >= 2:\n",
    "                    return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        uni = []\n",
    "        for s in astr:\n",
    "            if s in uni:\n",
    "                return False\n",
    "            else:\n",
    "                uni.append(s)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        seen=set()\n",
    "        \n",
    "        for elem in astr:\n",
    "            if elem in seen:\n",
    "                return False\n",
    "            else :seen.add(elem)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        return len(astr) == len(set(astr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        return len(astr) == len(set(astr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        chars = set()\n",
    "        for s in astr:\n",
    "            if s in chars:\n",
    "                return False\n",
    "            chars.add(s)\n",
    "        return True\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        m = {}\n",
    "        for i in astr:\n",
    "            if i not in m:\n",
    "                m[i] = i\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        mark = 0\n",
    "        for ch in astr:\n",
    "            move_bit = ord(ch) - ord('a')\n",
    "            if(mark & (1 << move_bit)) != 0:\n",
    "                return False\n",
    "            else:\n",
    "                mark |= (1 << move_bit)\n",
    "        return True\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        return len(astr)==len(set(astr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        dic = {}\n",
    "        for c in astr:\n",
    "            if c in dic:\n",
    "                dic[c] += 1\n",
    "            else:\n",
    "                dic[c] = 1\n",
    "        # end for\n",
    "\n",
    "        if sum(list(dic.values())) != len(dic):\n",
    "            return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        if len(astr)==0:\n",
    "            return True\n",
    "        occur=set()\n",
    "        for e in astr:\n",
    "            if e not in occur:\n",
    "                occur.add(e)\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isUnique(self, astr: str) -> bool:\n",
    "        import collections\n",
    "        s1 = collections.Counter(astr)\n",
    "        s2 = sorted(s1.values(), key=lambda x: x, reverse=True)\n",
    "        for v in s2:\n",
    "            if v > 1:\n",
    "              return False\n",
    "            else:\n",
    "              return True\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "  def isUnique(self, astr: str) -> bool:\n",
    "    mark = 0\n",
    "    for char in astr:\n",
    "      move_bit = ord(char) - ord('a')\n",
    "      if (mark & (1 << move_bit)) != 0:\n",
    "        return False\n",
    "      else:\n",
    "        mark |= (1 << move_bit)\n",
    "    return True\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
